//
//  WBStatusCell.swift
//  传智微博
//
//  Created by zhoujiming on 2017/2/16.
//  Copyright © 2017年 gmcc. All rights reserved.
//

import UIKit

class WBStatusCell: UITableViewCell {

    ///微博视图模型
    var viewModel: WBStatusViewModel? {
        didSet{
            // 设置微博文本
            statusLabel?.text = viewModel?.status.text
            // 设置姓名
            nameLabel.text = viewModel?.status.user?.screen_name
            
            //设置会员
            memberIconView.image = viewModel?.memberIcon
            // 认证图标
            vipIconView.image = viewModel?.vipIcon
            
            // 设置头像
            iconView.cz_setImage(urlString: viewModel?.status.user?.profile_image_url, placeholderImage: UIImage(named: "avatar_default_big"), isAvatar: true)
            
            toolBar.viewModel = viewModel
            
            // 配图视图模型
            pictureView.viewModel = viewModel
            // 调整配图视图高度
            //pictureView.heightCons.constant = viewModel?.pictureViewSize.height ?? 0
            //pictureTopCons.constant = 0
            
            // 设置配图视图的urls
            // 测试4张图像
//            if viewModel?.status.pic_urls?.count ?? 0 > 4 {
//                // 修改数组
//                var picUrls = viewModel!.status.pic_urls!
//                picUrls.removeSubrange((picUrls.startIndex + 4)..<picUrls.endIndex)
//                
//                pictureView.urls = picUrls
//                
//            }else{
//                pictureView.urls = viewModel?.status.pic_urls
//            }
            
            // pictureView.urls = viewModel?.picURLs
            
            retweetedLabel?.text = viewModel?.retweetedText
        }
    }
    /// 头像
    @IBOutlet weak var iconView: UIImageView!
    // 姓名
    @IBOutlet weak var nameLabel: UILabel!
    // 会员图标
    @IBOutlet weak var memberIconView: UIImageView!
    // 时间
    @IBOutlet weak var timeLabel: UILabel!
    // 来源
    @IBOutlet weak var sourceLabel: UILabel!
    // 认证图标
    @IBOutlet weak var vipIconView: UIImageView!
    // 正文
    @IBOutlet weak var statusLabel: UILabel!
    
    // 底部工具栏
    @IBOutlet weak var toolBar: WBStatusToolBar!
    
    // 配图视图
    @IBOutlet weak var pictureView: WBStatusPictureView!
    
    // 被转发微博的内容
    @IBOutlet weak var retweetedLabel: UILabel?
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        // 离屏渲染
        self.layer.drawsAsynchronously = true
        
        // 栅格化
        self.layer.shouldRasterize = true
        
        self.layer.rasterizationScale = UIScreen.main.scale
    }

    

}
